package com.zang.blogz.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zang.blogz.annotation.OptLog;
import com.zang.blogz.constant.OptTypeConstant;
import com.zang.blogz.entity.PhotoAlbum;
import com.zang.blogz.model.output.PhotoVO;
import com.zang.blogz.model.output.admin.AdminPhotoAlbumVO;
import com.zang.blogz.result.Result;
import com.zang.blogz.service.PhotoAlbumService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 相册 前端控制器
 * </p>
 *
 * @author 朵橙i
 * @since 2022-06-17
 */
@RestController
@RequestMapping("/blogz/photoAlbum")
@Api(tags = "相册模块")
public class PhotoAlbumController {

    @Autowired
    private PhotoAlbumService photoAlbumService;

    @GetMapping("/photoAlbumList")
    @ApiOperation(value = "获取相册列表", tags = "获取相册列表")
    public Result<List<PhotoAlbum>> photoAlbumList(){

        return Result.ok(photoAlbumService.list());
    }

    @GetMapping("/photoList")
    @ApiOperation(value = "根据相册id查询照片列表", tags = "前后台通用")
    public Result<PhotoVO> photoList(@RequestParam(value = "albumId") Integer albumId){

        return Result.ok(photoAlbumService.photoList(albumId));
    }

    @GetMapping("/admin/photoAlbumList")
    @ApiOperation(value = "查看后台相册列表", notes = "查看后台相册列表")
    public Result<IPage<AdminPhotoAlbumVO>> photoAlbumListAdmin(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                @RequestParam(name = "pageSize", defaultValue = "8") Integer pageSize){

        Page<AdminPhotoAlbumVO> page = new Page<>(pageNo, pageSize);

        return Result.ok(photoAlbumService.photoAlbumListAdmin(page));
    }

    @PostMapping("/admin/photoAlbum")
    @ApiOperation(value = "添加或修改相册", notes = "添加或修改相册")
    @OptLog(optType = OptTypeConstant.SAVE_OR_UPDATE)
    public Result<PhotoAlbum> saveOrUpdate(@RequestBody PhotoAlbum photoAlbum){

        return photoAlbumService.saveOrUpdatePhotoAlbum(photoAlbum);
    }

    @DeleteMapping("/admin/deletePhotoAlbum")
    @ApiOperation(value = "删除相册", notes = "删除相册")
    @OptLog(optType = OptTypeConstant.REMOVE)
    public Result<String> deletePhotoAlbum(@RequestParam(value = "photoAlbumId") Integer photoAlbumId){

        return photoAlbumService.deletePhotoAlbum(photoAlbumId);
    }



}
